(function(a) {
	a.fn.richcheckbox = function(k) {
		var d = a.extend({
			allBtn: false,
			checkAll: false,
			selected: "",
			type: "0"
		},
		k);
		var c = "";
		var g = a(this);
		var i = g.attr("name");
		var b = i.replace(/\./g, "\\.");
		var f = 0;
		var j = d.selected.split(",");
		var labClass = "";
		var lab2Class = "";
		var checkClass = "";
		if("0" == d.type || 0 == d.type){
			labClass = " richcheckbox2 richcheckbox2-otherBrowserChecked ";
			lab2Class = " richcheckbox2 ";
			checkClass = "richcheckbox2-otherBrowserChecked";
		}else {
			labClass = " richcheckbox otherBrowserChecked ";
			lab2Class = " richcheckbox ";
			checkClass = "otherBrowserChecked";
		}
		g.each(function(l) {
			var m = a(this);
			var _title = a(this).attr("title");
			if(undefined == _title){
				_title = a(this).attr("lab");
			}
			m.addClass("otherBrowser");
			if ("" != d.selected) {
				if ( - 1 != a.inArray(m.attr("value"), j)) {
					c = "<label class='" + labClass + a(this).attr("name") + "' title='" + _title + "'>" + a(this).attr("lab") + "</label>";
					m.prop("checked", true);
					f++;
				} else {
					c = "<label class='" + lab2Class + a(this).attr("name") + "' title='" + _title + "'>" + a(this).attr("lab") + "</label>";
					m.prop("checked", false);
				}
			} else {
				if (m.is(":checked") || d.checkAll) {
					c = "<label class='" + labClass + a(this).attr("name") + "' title='" + _title + "'>" + a(this).attr("lab") + "</label>";
					m.prop("checked", true);
					f++;
				} else {
					c = "<label class='" + lab2Class + a(this).attr("name") + "' title='" + _title + "'>" + a(this).attr("lab") + "</label>";
					m.prop("checked", false);
				}
			}
			m.wrap(c);
			m.click(function() {
				var n = a(this).closest("label");
				if (a(this).is(":checked")) {
					n.addClass(checkClass);
					f++;
					if (f == g.length) {
						a("#" + b).addClass(checkClass);
					}
				} else {
					n.removeClass(checkClass);
					$("#" + b).removeClass(checkClass);
					f--;
				}
			})
		});
		if (d.allBtn) {
			if("0" == d.type || 0 == d.type){
				var e = "<label class='richcheckbox2' id='" + i + "'>全选</label>";
				g.eq(0).closest(".richcheckbox2").before(e);
			}else{
				var e = "<label class='richcheckbox' id='" + i + "'>全选</label>";
				g.eq(0).closest(".richcheckbox").before(e);
			}
			if (f == g.length) {
				a("#" + b).addClass(checkClass);
			}
		}
		a("#" + b).click(function() {
			if ( - 1 != a(this).attr("class").indexOf(checkClass)) {
				a("." + b).removeClass(checkClass);
				a(this).removeClass(checkClass);
				g.prop("checked", false);
				f = 0;
			} else {
				a("." + b).addClass(checkClass);
				a(this).addClass(checkClass);
				g.prop("checked", true);
				f = g.length;
			}
		})
	};
	a.fn.richradio = function(d) {
		var e = a.extend({
			selected: "",
			type: "0"
		},
		d);
		var b = e.selected.split(",");
		var c = "";
		var g = a(this);
		var labClass = "";
		var lab2Class = "";
		var checkClass = "";
		if("0" == e.type || 0 == e.type){
			labClass = " richradio2 richradio2-otherBrowserChecked ";
			lab2Class = " richradio2 ";
			checkClass = "richradio2-otherBrowserChecked";
		}else {
			labClass = " richradio otherBrowserChecked ";
			lab2Class = " richradio ";
			checkClass = "otherBrowserChecked";
		}
		g.each(function(k) {
			var j = a(this);
			var h = j.attr("name");
			var _title = a(this).attr("title");
			if(undefined == _title){
				_title = a(this).attr("lab");
			}
			j.addClass("otherBrowser");
			if ("" != e.selected) {
				if ( - 1 != $.inArray(j.attr("value"), b)) {
					j.prop("checked", true);
					c = "<label class='" + labClass + h + "' for='" + h + "-" + k + "' title='" + _title + "'>" + j.attr("lab") + "</label>";
				} else {
					j.prop("checked", false);
					c = "<label class='" + lab2Class + h + "' for='" + h + "-" + k + "' title='" + _title + "'>" + j.attr("lab") + "</label>";
				}
			} else {
				if (j.is(":checked")) {
					c = "<label class='" + labClass + h + "' for='" + h + "-" + k + "' title='" + _title + "'>" + j.attr("lab") + "</label>";
				} else {
					c = "<label class='" + lab2Class + h + "' for='" + h + "-" + k + "' title='" + _title + "'>" + j.attr("lab") + "</label>";
				}
			}
			j.prop("id", h + "-" + k);
			j.wrap(c);
			j.click(function() {
				var i = a(this).attr("name");
				var l = a(this).closest("label");
				a("." + i).removeClass(checkClass);
				l.addClass(checkClass);
			})
		})
	};
	a.fn.richselect = function(e) {
		var g = a.extend({
			type: "single",
			selected: "",
			width: "220px"
		},
		e);
		var d = a(this);
		var i = d.find("option");
		var placeholder = i.eq(0).text();
		d.addClass("otherBrowser")
		var h = "<div class='richselect' id='" + d.attr("id") + "-rich'><span class='richplaceholder'>" + placeholder + "</span><ul>";
		i.each(function(i, ele) {
			if(i > 0){
				var j = a(this);
				h += "<li value='" + j.val() + "'>" + j.text() + "</li>";
			}
		});
		h += "</ul></div>";
		d.after(h);
		var f = d.next(".richselect");
		f.css({
			"width": g.width
		});
		f.find("ul>li").addClass("unchecked");
		if ("single" == g.type) {
			d.find("option").prop("selected", false);
			if ("" != g.selected) {
				f.find("ul>li").each(function(j) {
					if (g.selected == a(this).attr("value")) {
						f.find(".richplaceholder").text(a(this).text());
						d.find("option[value='" + a(this).attr("value") + "']").prop("selected", true);
						return false;
					}
				})
			} else {
				d.find("option").eq(0).prop("selected", true);
			}
			f.on("click", ".richplaceholder",
					function(k) {
				var j = a(this).closest(".richselect");
				if (!j.hasClass("is-open")) {
					a(".richselect").removeClass("is-open");
					j.addClass("is-open");
					a(this).find(".is-open").not(j).removeClass("is-open");
				} else {
					j.removeClass("is-open");
				}
				k.stopPropagation()
			}).on("click", "ul>li",
					function() {
				var j = a(this).closest(".richselect");
				if (a(this).text() != j.find(".richplaceholder").text()) {
					j.removeClass("is-open").find(".richplaceholder").text(a(this).text());
					d.find("option").prop("selected", false);
					d.find("option[value='" + a(this).attr("value") + "']").prop("selected", true);
					d.trigger("change");
				}
			})
		} else {
			if ("multi" == g.type) {
				var c = [];
				d.prop("multiple", "multiple");
				d.find("option").prop("selected", false);
				if ("" != g.selected) {
					if ("all" != g.selected) {
						var b = g.selected.split(",");
						f.find("ul>li").each(function(l) {
							for (var k = 0; k < b.length; k++) {
								if (b[k] == a(this).attr("value")) {
									a(this).removeClass("unchecked").addClass("checked");
									c.push(a(this).text());
									d.find("option[value='" + a(this).attr("value") + "']").prop("selected", true)
								}
							}
						})
					} else {
						f.find("ul>li").each(function(j) {
							a(this).removeClass("unchecked").addClass("checked");
							c.push(a(this).text());
							d.find("option[value='" + a(this).attr("value") + "']").prop("selected", true)
						})
					}
					f.find(".richplaceholder").text(c)
				}
				f.on("click", ".richplaceholder",
						function(k) {
					var j = a(this).closest(".richselect");
					if (!j.hasClass("is-open")) {
						a(".richselect").removeClass("is-open");
						j.addClass("is-open");
						a(this).find(".is-open").not(j).removeClass("is-open");
					} else {
						j.removeClass("is-open");
					}
					k.stopPropagation();
				}).on("click", "ul>li",
						function() {
					var j = a(this).closest(".richselect");
					if ( - 1 != a(this).attr("class").indexOf("unchecked")) {
						a(this).removeClass("unchecked").addClass("checked");
						c.push(a(this).text());
						d.find("option[value='" + a(this).attr("value") + "']").prop("selected", true);
						j.find(".richplaceholder").text(c)
					} else {
						if ( - 1 != a(this).attr("class").indexOf("checked")) {
							a(this).removeClass("checked").addClass("unchecked");
							c.removeByValue(a(this).text());
							d.find("option[value='" + a(this).attr("value") + "']").prop("selected", false);
							if (c.length > 0) {
								j.find(".richplaceholder").text(c);
							} else {
								j.find(".richplaceholder").text(placeholder);
							}
						}
					}
				})
			}
		}
		$("body").on("click",
				function(l) {
			var j = l.srcElement ? l.srcElement: l.target;
			var k = a(j).closest(".richselect");
			if (undefined != a(k).attr("class") && -1 != a(k).attr("class").indexOf("richselect")) {
				return
			} else {
				a(".richselect").removeClass("is-open");
			}
		})
	};
	a.fn.richhex = function(b) {
		var d = a.extend({
			length: "60",
			color: "#53a57e"
		},
		b);
		var c = 0.866;
		var e = a(this);
		e.each(function(h) {
			var f = a(this);
			var g = f.text();
			var j = "<div class='rich-hex-top'></div>        <div class='rich-hex-center'></div>        <div class='rich-hex-bottom'></div>";
			f.html(j);
			f.find(".rich-hex-top").css({
				"border-bottom": (d.length / 2) + "px solid " + d.color,
				"border-left": (c * d.length) + "px solid transparent",
				"border-right": (c * d.length) + "px solid transparent"
			});
			f.find(".rich-hex-center").css({
				"width": (c * d.length * 2) + "px",
				"height": d.length,
				"background": d.color,
				"line-height": d.length + "px"
			});
			f.find(".rich-hex-bottom").css({
				"border-top": (d.length / 2) + "px solid " + d.color,
				"border-left": (c * d.length) + "px solid transparent",
				"border-right": (c * d.length) + "px solid transparent"
			});
			f.find(".rich-hex-center").text(g)
		})
	};
	a.fn.getRadioVal = function(b) {
		var _name = $(this).attr("name");
		return $("input:radio[name='"+_name+"']:checked").val();
	};
	a.fn.getCheckboxVal = function(b) {
		var _name = $(this).attr("name");
		var arr = [];
		$("input:checkbox[name='"+_name+"']:checked").each(function(i, ele){
			arr.push(ele.value);
		});
		return arr;
	};
	a.fn.getSelectVal = function(b) {
		var _id = $(this).attr("id");
		var arr = [];
		$("#"+_id+" option:selected").each(function(i, ele){
			arr.push(ele.value);
		});
		return arr;
	};
	Array.prototype.removeByValue = function(c) {
		for (var b = 0; b < this.length; b++) {
			if (this[b] == c) {
				this.splice(b, 1);
				break
			}
		}
	}
})(jQuery);